package org.nowcoder.leetcode.BSearch;

import java.util.Arrays;

/**
 * Title  : 744. Find Smallest Letter Greater Than Target
 * Source : https://leetcode.cn/problems/find-smallest-letter-greater-than-target/description/
 * Author : XrazYang
 * Date   : 2023-10-30
 */

public class LeetCode_744 {
    public char nextGreatestLetter(char[] letters, char target) {
        char c = (char) (target + 1);
        while (c <= 'z') {
            int i = Arrays.binarySearch(letters, c);
            if (i < 0) {
                c = (char) (c + 1);
            } else {
                return letters[i];
            }
        }
        return letters[0];
    }
}
